<!-- create jishenghua-->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('setailManagement.documentNo')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input :placeholder="$t('setailManagement.pleaseEnterTheDocumentNumber')"
                    v-model="queryParam.number"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('setailManagement.documentDate')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-range-picker style="width:100%" v-model="queryParam.createTimeRange" format="YYYY-MM-DD"
                    :placeholder="[$t('setailManagement.startTime'), $t('setailManagement.endTime')]" 
                    @change="onDateChange" @ok="onDateOk" />
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item :label="$t('manuManagement.operator')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select :placeholder="$t('manuManagement.selectOperator')" showSearch optionFilterProp="children"
                            v-model="queryParam.creator">
                    <a-select-option v-for="(item, index) in userList" :key="index" :value="item.id">
                      {{ item.userName }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">{{ $t('setailManagement.query') }}</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">{{ $t('setailManagement.reset') }}</a-button>
                  <a @click="handleToggleSearch" style="margin-left: 8px">
                    {{ toggleSearchStatus ? $t('setailManagement.putAway') : $t('setailManagement.open') }}
                    <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                  </a>
                </a-col>
              </span>
              <template v-if="toggleSearchStatus">
                <a-col :md="6" :sm="24">
                  <a-form-item :label="$t('manuManagement.customer')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input :placeholder="$t('manuManagement.customer')"
                             v-model="queryParam.remark"></a-input>
                  </a-form-item>
                </a-col>
              </template>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin-top: 5px">
<!--          <a-button v-if="btnEnableList.indexOf(1) > -1" @click="myHandleAdd" type="primary" icon="plus">{{-->
<!--              $t('manuManagement.newlyAdded')-->
<!--          }}</a-button>-->
<!--          <a-dropdown>-->
<!--            <a-menu slot="overlay">-->
<!--              <a-menu-item key="1" v-if="btnEnableList.indexOf(1) > -1" @click="batchDel"><a-icon type="delete" />{{-->
<!--                  $t('manuManagement.delete')-->
<!--              }}</a-menu-item>-->
<!--              &lt;!&ndash; <a-menu-item key="2" v-if="btnEnableList.indexOf(2)>-1" @click="batchSetStatus(1)"><a-icon type="check"/>{{$t('manuManagement.toExamine')}}</a-menu-item>-->
<!--              <a-menu-item key="3" v-if="btnEnableList.indexOf(7)>-1" @click="batchSetStatus(0)"><a-icon type="stop"/>{{$t('manuManagement.DeApproval')}}</a-menu-item> &ndash;&gt;-->
<!--            </a-menu>-->
<!--            <a-button>-->
<!--              {{ $t('manuManagement.batchOperation') }} <a-icon type="down" />-->
<!--            </a-button>-->
<!--          </a-dropdown>-->
          <ColumnsSetting @columnsChange="columnsChange" :columns="columns"></ColumnsSetting>
          <a-tooltip placement="left" :title="$t('manuManagement.theOperations')" slot="action">
            <a-icon v-if="btnEnableList.indexOf(1) > -1" type="question-circle" style="font-size:20px;float:right;" />
          </a-tooltip>
          <a-button v-if="btnEnableList.indexOf(3) > -1" :loading="downLoading" style="margin-left: 8px" @click="exportExcel" icon="download">{{$t('reportQuery.export')}}</a-button>
          <a-button v-if="btnEnableList.indexOf(5) > -1"  style="margin-left: 8px" v-print="'#reportPrint'" icon="printer">{{$t('reportQuery.print')}}</a-button>
          <a-button v-if="btnEnableList.indexOf(5) > -1"  style="margin-left: 8px" @click="generatePrintData" icon="printer">{{$t('inPrint.other') + $t('reportQuery.print')}}</a-button>
        </div>
        <!-- table区域-begin -->
        <section ref="print" id="reportPrint">
          <a-table :customRow="rowClick" ref="table" size="middle" bordered rowKey="id" :columns="columns"
            :dataSource="dataSource" :pagination="ipagination" :scroll="scroll" :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" @change="handleTableChange">
            <span slot="totalTaxLastMoney" slot-scope="text, record">
              <p>{{ toThousandsNoZero(record.discountMoney + record.discountLastMoney) }}</p>
            </span>
            <span slot="action" slot-scope="text, record">
<!--               <a @click="myHandleDetail(record, $t('manuManagement.salesOrder'))">{{ $t('manuManagement.check') }}</a>-->
<!--              <a-divider v-if="btnEnableList.indexOf(1) > -1" type="vertical" />-->
              <a v-if="btnEnableList.indexOf(1) > -1" @click="myHandleEdit(record)">{{ $t('setailManagement.settlement') }}</a>
              <a-divider v-if="btnEnableList.indexOf(1) > -1" type="vertical" />
<!--              <a v-if="btnEnableList.indexOf(1) > -1" @click="myHandleCopyAdd(record)">{{ $t('manuManagement.copy')-->
<!--              }}</a>-->
<!--              <a-divider v-if="btnEnableList.indexOf(1) > -1" type="vertical" />-->
<!--              <a-popconfirm v-if="btnEnableList.indexOf(1) > -1" :title="$t('manuManagement.areDelete')"-->
<!--                @confirm="() => myHandleDelete(record)">-->
<!--                <a>{{ $t('manuManagement.delete') }}</a>-->
<!--              </a-popconfirm>-->
            </span>
            <template slot="customRenderStatus" slot-scope="status">
              <a-tag v-if="status == '0'" color="red">{{ $t('setailManagement.Unsettled') }}</a-tag>
              <a-tag v-if="status == '1'" color="green">{{ $t('setailManagement.Settled') }}</a-tag>
              <a-tag v-if="status == '2'" color="cyan">{{ $t('manuManagement.completeSales') }}</a-tag>
              <a-tag v-if="status == '3'" color="blue">{{ $t('manuManagement.partialSales') }}</a-tag>
            </template>
          </a-table>
        </section>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <retail-sale-modal ref="modalForm" @ok="modalFormOk"></retail-sale-modal>
        <bill-detail ref="modalDetail"></bill-detail>
      </a-card>
    </a-col>
  </a-row>
</template>
<script>
import RetailSaleModal from './modules/RetailSaleModal'
import BillDetail from './dialog/BillDetail'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { BillListMixin } from './mixins/BillListMixin'
import { getCurrentSystemConfig } from '@/api/api'
import JDate from '@/components/jeecg/JDate'
import Vue from 'vue'
export default {
  name: "SaleOrderList",
  mixins: [JeecgListMixin, BillListMixin],
  components: {
    RetailSaleModal,
    BillDetail,
    JDate
  },
  data() {
    return {
      // 查询条件
      queryParam: {
        number: "",
        materialParam: "",
        type: '出库',
        subType: '零售销售',
        roleType: Vue.ls.get('roleType'),
        organId: "",
        depotId: "",
        creator: "",
        purchaseStatus: "1",
        remark: "", 
      },
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18,
        offset: 1
      },
      // 表头
      columns: [
        {title: this.$t('defaultTranslate.lineNumber'), dataIndex: 'rowIndex', width:60, align:"center", customRender: (t,r,index) => t || (parseInt(index) + 1)},
        { title: this.$t('manuManagement.customer'), dataIndex: 'remark', width: 120, ellipsis: true },
        {
          title: this.$t('manuManagement.documentNo'), dataIndex: 'number', width: 160,
          customRender: function (text, record, index) {
            if (record.linkNumber) {
            } else {
              return text;
            }
          }
        },
        // {
        //   title: this.$t('manuManagement.productInformation'), dataIndex: 'materialsList', width: 220, ellipsis: true,
        //   customRender: function (text, record, index) {
        //     if (text) {
        //       return text.replace(",", "，");
        //     }
        //   }
        // },
        { title: this.$t('manuManagement.documentDate'), dataIndex: 'operTimeStr', width: 145 },
        { title: this.$t('manuManagement.operator'), dataIndex: 'loginName', width: 80, ellipsis: true },
        // { title: this.$t('manuManagement.totalAmount'), dataIndex: 'totalPrice', width: 80 },
        // {
        //   title: this.$t('manuManagement.totalTaxIncluded'), dataIndex: 'totalTaxLastMoney', width: 80,
        //   scopedSlots: { customRender: 'totalTaxLastMoney' },
        //   // customRender:function (text,record,index) {
        //   //   if(record.discountLastMoney) {
        //   //     return (record.discountMoney + record.discountLastMoney).toFixed(2);
        //   //   } else {
        //   //     return record.totalPrice;
        //   //   }
        //   // }
        // },
        { title: this.$t('manuManagement.totalAmount'), dataIndex: 'totalPrice', width: 80 },
        {
          title: this.$t('setailManagement.amountCollected'),
          dataIndex: 'changeAmount',
          width: 80
        },
        { title: this.$t('setailManagement.giveChange'), dataIndex: 'backAmount', width: 50 },
        { title: this.$t('commodityManagement.totalMerchandise'), dataIndex: 'total', width: 50 },
        {
          title: this.$t('manuManagement.state'), dataIndex: 'status', width: 70, align: "center",
          scopedSlots: { customRender: 'customRenderStatus' }
        },
        // {
        //   title: this.$t('manuManagement.operation'),
        //   dataIndex: 'action',
        //   align: "center", width: 150,
        //   scopedSlots: { customRender: 'action' },
        // }
      ],
      url: {
        list: "/depotHead/list",
        delete: "/depotHead/delete",
        deleteBatch: "/depotHead/deleteBatch",
        deApprovalUrl:'/depotHead/batchCounterAuditStatus',
        batchSetStatusUrl: "/depotHead/batchSetStatus"
      }
    }
  },
  created() {
    this.initCustomer()
    this.initUser()
    this.getSystemConfig()
  },
  computed: {
  },
  methods: {
    rowClick(record, index) {
      return {
        on: {
          click: () => {
          },
          dblclick: () => {
            console.log('双击了我')
            this.myHandleDetail(record, '仓库销售')
          },
        }
      }
    },
    toThousandsNoZero(num) {
      return num ? ((isNaN(parseFloat(num.toString().replace(/,/g, ""))) ? 1 : parseFloat(num.toString().replace(/,/g, "")))).toFixed(2).toString().replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) {
        return $1 + ",";
      }) : "";
    },
    getSystemConfig() {
      getCurrentSystemConfig().then((res) => {
        if (res.code === 200 && res.data) {
          let purchaseBySaleFlag = res.data.purchaseBySaleFlag
          let statusIndex = 0
          for (let i = 0; i < this.columns.length; i++) {
            if (this.columns[i].dataIndex === 'purchaseStatus') {
              statusIndex = i
            }
          }
          if (purchaseBySaleFlag === "0") {
            if (statusIndex > 0) {
              this.columns.splice(statusIndex, 1)
            }
          } else {
            if (statusIndex === 0) {
              // let purchaseStatusObj = {
              //   title: this.$t('manuManagement.progress'), dataIndex: 'purchaseStatus', width: 70, align: "center",
              //   scopedSlots: { customRender: 'customRenderPurchaseStatus' }
              // }
              this.columns.splice(8, 0, purchaseStatusObj)
            }
          }
        }
      })
    },
    searchQuery() {
      this.loadData(1)
      this.getSystemConfig()
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less'
</style>